﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XoLib.Manager
{

    /// <summary>
    /// Registrator of class
    /// </summary>
    /// <example> new ClassManager.ProcessClass( "Truc.Pol", 1); </example>/// 
    public class ClassRegistrator : TemplateRegistrator<IExeClass>
    {
        private static readonly ClassRegistrator instance = new ClassRegistrator();

        /// <summary>
        ///  
        /// </summary>
        public static ClassRegistrator Instance
        {
            get
            {
                return instance;
            }
        }

        /// <summary>
        ///  Constructor
        /// </summary>
        public ClassRegistrator():
            base()
        {
        }


        internal override IExeClass AddInDic(Type ClassType, int Code, string Name)
        {

            if (!typeof(IExeClass).IsAssignableFrom(ClassType))
                return default(IExeClass);

            var tClass = (IExeClass)Activator.CreateInstance(ClassType);

            if (typeof(IExeClass).IsAssignableFrom(tClass.GetType()))
                return tClass;

            return default(IExeClass);
        }

    }
}


